home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
nn.zip
/
PACK_DAT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-29
|
2KB
|
109 lines
#include "config.h"
/* #define DATE_TEST /* never define this !! */
/*
* Calculate an approximate "time_stamp" value for a date
* string. The actual value is not at all critical,
* as long as the "ordering" is ok.
*
* The result is NOT a time_t value, i.e. ctime() will
* not produce the original Date string.
*
* The date must have format: [...,] [D]D Mmm YY hh:mm:ss GMT
*/
pack_date(destp, date)
time_stamp *destp;
char *date;
{
register time_stamp res;
register int min, hour, day, mon, year;
*destp = 0;
if (date == NULL) return;
if ((day = next_int(&date)) == 0) return;
while (*date && isspace(*date)) date++;
switch (*date++) {
case 'J':
if (*date++ == 'a') { mon = 0; break; }
if (*date++ == 'n') { mon = 5; break; }
mon = 6; break;
case 'F':
mon = 1; break;
case 'M':
if (*++date == 'r') { mon = 2; break; }
mon = 4; break;
case 'A':
if (*date++ == 'p') { mon = 3; break; }
mon = 7; break;
case 'S':
mon = 8; break;
case 'O':
mon = 9; break;
case 'N':
mon = 10; break;
case 'D':
mon = 11; break;
default:
return;
}
year = next_int(&date);
hour = next_int(&date);
min = next_int(&date);
year -= 87; /* base is 1987 */
if (year < 0) year += 100;
res = (year * 12 + mon) * 31 + day - 1;
res *= 24 * 60;
res += (hour * 60) + min;
*destp = res;
}
static next_int(dp)
char **dp;
{
register char *str = *dp;
register i;
while (*str && !isdigit(*str)) str++;
i = 0;
while (*str && isdigit(*str))
i = (i * 10) + *str++ - '0';
*dp = str;
return i;
}
#ifdef DATE_TEST
main()
{
char buffer[128];
char *dp;
unsigned long t;
while (fgets(buffer, 128, stdin)) {
dp = strchr(buffer, ':');
if (dp == NULL) continue;
dp++;
while (isspace(*dp)) dp++;
pack_date(&t, dp);
printf("%lu\t%s\n", t, dp);
}
nn_exit(0);
}
#endif